#include "light.h"
#include "globalvars.h"

#include "cmsis_os2.h"
#include "ohos_init.h"

int g_led_flag = 0;

void Light_task(void)
{
    int light = 0;
    while (1) 
    {
        Read_light(&light);
        if(light > 1000)
        {
            g_led_flag = 0;
        }
        if(light < 500)
        {
            g_led_flag = 1;
        }
    }
}

/** 安防任务创建函数 **/
void Light_entry(void)
{
    usleep(3*1000*1000); //延时3S
    
    osThreadAttr_t attr;  //任务属性的结构体

    attr.name = "Light_task";    //任务名称
    attr.stack_size = 1024;  //任务的内存大小
    attr.priority = 25;          //任务的优先级

    //创建任务
    if (osThreadNew((osThreadFunc_t)Light_task, NULL, &attr) == NULL) 
    {
        //任务创建失败
        printf("  Failed to create Light_task!\r\n");
    }
    //任务创建成功
    printf("  Succeed to create Light_task!\r\n");
}

/** 让系统运行指定的函数 **/
SYS_RUN(Light_entry);